package com.hboxs.asl.entity;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

import javax.persistence.*;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by XXX on 2016/12/26
 * Entity - 退货记录
 */
@Entity
@Table(name = "xx_returns_record")
@SequenceGenerator(name = "sequenceGenerator", sequenceName = "xx_returns_record_sequence")
public class ReturnsRecord extends BaseEntity {

    private static final long serialVersionUID = -2412067710691929924L;

    public enum Status {

        /**
         * 申请中
         */
        apply,

        /**
         * 拒绝
         */
        reject,

        /**
         * 已处理
         */
        deal;

        private static Map<String, ReturnsRecord.Status> map = new HashMap<>();

        static {
            map.put("申请中", apply);
            map.put("拒绝", reject);
            map.put("已处理", deal);
        }

        @JsonCreator
        public static Status forValue(String value) {
            return map.get(value);
        }

        @JsonValue
        public String toValue() {
            for (Map.Entry<String, Status> entry : map.entrySet()) {
                if (entry.getValue() == this) {
                    return entry.getKey();
                }
            }
            return "";
        }
    }

    /**
     * 选择的退货原因
     */
    public enum Reason {

        /**
         * 商品问题
         */
        product,

        /**
         * 购买错误
         */
        mistake,

        /**
         * 不想买
         */
        nowant,

        /**
         * 没有原因
         */
        no;

        private static Map<String, ReturnsRecord.Reason> map = new HashMap<>();

        static {
            map.put("商品问题", product);
            map.put("购买错误", mistake);
            map.put("不想买", nowant);
            map.put("没有原因", no);
        }

        @JsonCreator
        public static Reason forValue(String value) {
            return map.get(value);
        }

        @JsonValue
        public String toValue() {
            for (Map.Entry<String, Reason> entry : map.entrySet()) {
                if (entry.getValue() == this) {
                    return entry.getKey();
                }
            }
            return "";
        }
    }

    /**
     * 退货的会员
     */
    private Member member;

    /**
     * 退货状态
     */
    private Status status;

    /**
     * 订单项
     */
    private OrderItem orderItem;

    /**
     * 数量
     */
    private Integer quantity;

    /**
     * 原因
     */
    private Reason reason;

    /**
     * 详细描述
     */
    private String description;

    @ManyToOne(fetch = FetchType.LAZY)
    public Member getMember() {
        return member;
    }

    public void setMember(Member member) {
        this.member = member;
    }

    /**
     * 获取退货状态
     *
     * @return 退货状态
     */
    public Status getStatus() {
        return status;
    }

    /**
     * 设置退货状态
     *
     * @param status 退货状态
     */
    public void setStatus(Status status) {
        this.status = status;
    }

    /**
     * 获取要退货的订单项
     *
     * @return 退货的订单项
     */
    @OneToOne(fetch = FetchType.LAZY)
    public OrderItem getOrderItem() {
        return orderItem;
    }

    /**
     * 设置要退货的订单
     *
     * @param orderItem 退货的订单项
     */
    public void setOrderItem(OrderItem orderItem) {
        this.orderItem = orderItem;
    }

    /**
     * 获取要退货的数量
     *
     * @return 数量
     */
    public Integer getQuantity() {
        return quantity;
    }

    /**
     * 设置要数量
     *
     * @param quantity 数量
     */
    public void setQuantity(Integer quantity) {
        this.quantity = quantity;
    }

    /**
     * 获取原因
     *
     * @return 原因
     */
    public Reason getReason() {
        return reason;
    }

    /**
     * 设置原因
     *
     * @param reason 原因
     */
    public void setReason(Reason reason) {
        this.reason = reason;
    }

    /**
     * 获取原因
     *
     * @return 原因
     */
    public String getDescription() {
        return description;
    }

    /**
     * 设置原因
     *
     * @param description 原因
     */
    public void setDescription(String description) {
        this.description = description;
    }

}
